<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="cache-control" content="no-cache"/>
<title>权限管理</title>
<link href="../style/main.css" rel="stylesheet" type="text/css" />
<link type="text/css" rel="stylesheet"  href="../style/style.css" />
<script type="text/javascript" src="../Scripts/validator.js"></script>
<style>
body{ padding:10px}
</style>
<script type="text/javascript" src="../Scripts/jquery.js"></script>
<script type="text/javascript">
function goToEdit(){
	var insuranceNumber = document.getElementById("insuranceNum").value;
	if(insuranceNumber == ""){
		alert("请选择要编辑的险种！");
		return;
	}
	window.location.href="insurancetypeAction!findInsurancetype.action?insurancetype.insuranceNumber="+insuranceNumber;
	return false;
}
function changeCompany(){
	var companyList =  document.getElementById("company");
	var companyNum = companyList.options[companyList.selectedIndex].value;
	if(companyNum == "")
		return;
	$.post("/WITAgent/Product/findSubcompanyByCompanyAction.action",{companyNum:companyNum},function(data){
		var subcompanyList = document.getElementById("subcompany");
		while(subcompanyList.options.length > 0){
			subcompanyList.remove(0);
		}
		var op = document.createElement("option");
            op.value = "";
            op.text = "--全部--";
            subcompanyList.options.add(op);
		for(var i=0;i<data.length;i++){
            op = document.createElement("option");
            op.value = data[i].insuranceNumber;
            op.text = data[i].insuranceName;
            subcompanyList.options.add(op);
        }
	},"json");
}
function changeSubcompany(){
	var subcompanyList =  document.getElementById("subcompany");
	var subcompanyNum = subcompanyList.options[subcompanyList.selectedIndex].value;
	var insuranceNum = document.getElementById("insuranceNum").value;
	if(subcompanyNum == "")
		return;
	$.post("/WITAgent/Product/insurancedefAction!findInsurancedefBySubcompInsurance.action",{subcompanyId:subcompanyNum,insuranceNumber:insuranceNum},function(data){
		document.getElementById("insurancedef").value=data.insuranceId;
		document.getElementById("insuranceNumMark").value=data.insuranceNumMark;
		document.getElementById("discountrate").value=data.discountrate;
		document.getElementById("agencyrate").value=data.agencyrate;
		document.getElementById("commrate").value=data.commrate;
		document.getElementById("specificalagree").value=data.specificalagree;
		alert(data.projectList);
		var pros = data.projectList;
		var pros = data.projectList;
		var ls_t=document.getElementById("projects");
		while(ls_t.rows.length > 1){
			ls_t.deleteRow(1);
		}
		for(var i = 0; i < pros.length; i ++){
		var newRow = "<tr align='center'>"+ "<td><input style='border:none' type='radio' value='"+pros[i].projectNum+"' name='projectId'/></td>"+"<td>"+pros[i].projectNum+"</td>"+"<td>"+pros[i].projectName+"</td>"+"<td>"+pros[i].insurancerate+"</td>"+"<td>"+pros[i].flag+"</td>"+"<tr>";
		$(ls_t).append(newRow);
		
		}
	},"json");
}
function addProject(){
	var pros = document.getElementById("insurancedef");
	if(pros.value == ""){
		alert( "当前无选定险种！");
		return false;
	}
	window.location.href = "Insurance_program_new.jsp?insuranceId="+pros.value;
	return false;
}
function editProject(){
	var pros = document.getElementsByName("projectId");
	var count = 0;
	var index = 0; 
	
	for(var i = 0; i < pros.length; i ++){
		if(pros[i].checked){
			count ++;
			index = i;
		}
	}
	if(count == 1){
		window.location.href = "projectAction!findProject.action?project.projectNum="+pros[index].value;
	}
	else{
		window.alert("请选择一个编辑选项");
	}
	return false;
}

function delProject(){
	var pros = document.getElementsByName("projectId");
	var count = 0;
	var index = 0; 
	for(var i = 0; i < pros.length; i ++){
		if(pros[i].checked){
			count ++;
			index = i;
		}
	}
	if(count == 1){
		window.location.href = "projectAction!deleteProject.action?project.projectNum="+pros[index].value;
	}
	else{
		window.alert("请选择一个编辑选项");
	}
	return false;
}
</script>
</head>

<body><table width="700" align="left" cellpadding="0" cellspacing="0"class="table3">
    <tr>
        <td width="5%" align="center" ><span class="clientinfo_but" ><a href="insurancetypeAction!findAllInsuranceMark.action" >增加险种</a></span></td>
      <td width="5%" align="center" ><span class="clientinfo_but" ><a href="#" onclick="goToEdit()">修改险种</a></span></td>
      <td width="5%" align="center" ><span class="clientinfo_but" ><a href="#" >删除险种</a></span></td>
        <td width="5%" align="center" ><span class="clientinfo_but" ><a href="#" >删除公司险种</a></span></td>
        <td width="5%" align="center" ><span class="clientinfo_but" ><a href="Insurance_program_new.jsp#" onclick="return addProject()">增加项目</a></span></td>
        <td width="5%" align="center" ><span class="clientinfo_but" ><a href="Insurance_program_edit.jsp#" onclick="return editProject()">修改项目</a></span></td>
      <td width="5%" align="center" ><span class="clientinfo_but" ><a href="#" onclick="delProject()">删除项目</a></span></td>
    </tr>
</table>
<div class=" clear"></div>
<table width="700" border="0" align="left" cellpadding="0" cellspacing="0" class="table">
  <tr>
    <td><div class="mainarea">
      <div class="search">
      
      <s:form action="insurancedefAction!addInsurancedef" method="post" theme="simple"  onsubmit="return Validator.Validate(this,1);">
        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table4">
          <tr>
            <td width="28%" colspan="2" bgcolor="#BBD2F7" class="title">险种资料</td>
          </tr>
          <tr>
            <td height="818" colspan="2">
            <table width="100%" border="0" cellspacing="2" cellpadding="0">
              
              <tr>
                <td width="24%" align="left" >险种编号：</td>
                <td colspan="3" align="left" ><input type="hidden" value="<s:property value='insurancedef.insuranceId'/>" id="insurancedef"/><s:textfield name="insurancedef.insurancetype.insuranceNumber" id="insuranceNum"/></td>
              </tr>
              <tr>
                <td align="left" >险种名称：</td>
                <td colspan="3" align="left" ><s:textfield id="insuranceName" name="insurancedef.insurancetype.insuranceName" cssStyle="width:150px" /></td>
              </tr>
              <tr>
                <td align="left" >保险公司：</td>
                <td colspan="3" align="left" ><s:select name="insurancedef.subcompany.company.companyNum" id="company" headerKey="''" headerValue="--全部--" list="companyList" listKey="companyNum" listValue="shortName" cssStyle="width:150px" onchange="changeCompany()">
                </s:select></td>
              </tr>
              <tr>
                <td align="left" >分支公司：</td>
                <td colspan="3" align="left" ><s:select list="subcompanyList" name="insurancedef.subcompany.subcompanyId" cssStyle="width:150px" id="subcompany"  headerKey="''" headerValue="--全部--" onchange="changeSubcompany()" listKey="subcommpanyId" listValue="sfullName">
			</s:select></td>
              </tr>
              <tr>
                <td align="left" >保险编号标识：</td>
                <td width="29%" align="left" ><s:textfield name="insurancedef.insuranceNumMark" cssStyle="width:150px" id="insuranceNumMark" dataType="Require" msg="请输入保险编号标识"/></td>
                <td align="left" >折扣系数：</td>
                <td align="left" ><s:textfield name="insurancedef.discountrate"  id="discountrate" dataType="Require" msg="请输入折扣系数"/></td>
              </tr>
              
              <tr>
                <td align="left" >代理费比例：</td>
                <td align="left" ><s:textfield name="insurancedef.agencyrate" id="agencyrate" dataType="Require" msg="请输入代理费比例"/></td>
                <td width="19%" align="left" >佣金比例：</td>
                <td width="28%" align="left" ><s:textfield name="insurancedef.commrate"  id="commrate" dataType="Require" msg="请输入佣金比例"/></td>
              </tr>
              <tr>
                <td align="left" >特别约定：</td>
                <td colspan="3" align="left" ><s:textfield name="insurancedef.specificalagree" cssStyle="width:300px"  id="specificalagree" dataType="Require" msg="请输入特别约定"/></td>
              </tr>
              <tr>
                <td align="left" >标的类别 ：</td>
                <td align="left"><s:textfield name="insurancedef.insurancetype.mark.markName" cssStyle="width:300px" id="markName"/></td>
                <td width="19%" align="left">&nbsp;</td>
                <td align="left">&nbsp;</td>
              </tr>
              <tr>

                <td colspan="4" align="center">
                <s:submit  value="保   存"  cssClass="btn"/>
                 &nbsp;&nbsp;&nbsp;&nbsp;
                <s:reset  value="取   消"  cssClass="btn"/></td>
              </tr>
            </table>
              </td>
          </tr>
        </table>
        </s:form>
        
        <table width="100%" cellpadding="0" cellspacing="1"  class="table4" id="projects">
        	<tr bgcolor="#BBD2F7">
            <th width="139">&nbsp;</th>
            <th width="150">项目编号</th>
            <th width="233">项目名称</th>
            <th width="76">保险费率</th>
            <th width="72">是否主险</th>
            </tr>
            <s:iterator value="projectList">
             <tr align="center">
                <td><input type="radio" value="<s:property value='projectNum'/>" name="projectId" style="border:none"/></td>
                <td><s:property value='projectNum'/></td>
                <td><s:property value='projectName'/></td>
                <td><s:property value='insurancerate'/></td>
                <td><s:if test="flag">是<s:else>否</s:else></s:if></td>
             </tr>
             </s:iterator>
            </table>
        </div>
    </div></td>
  </tr>
</table>
</body>
</html>